<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

abstract class m_backoffice_extends_FrontAction extends f_core_Action
{
    public function getRequestDocument()
    {
        $docId = $this->getRequestParameter('docId');
        $docLang = $this->getRequestParameter('docLang', $this->getContext()->getDefaultLang());

        if(!is_null($docId) && !is_null($docLang))
        {
            return $this->getDocumentProvider()->getByUniqueId($docId, $docLang);
        }

        return null;
    }

    public function redirect404()
    {
        $page = $this->getContext("currentPage")->setRedirect("404");
        $this->updateContext("frontOffice", $page);
    }

    public function getPagination($document, $numPage, $nbDoc, $nbDocTot)
    {
        if(!is_null($nbDoc) && $nbDoc > 0)
        {
            $nbPageTot = ceil($nbDocTot/$nbDoc);
            $this->addToModel('nbPageTot', $nbPageTot);
            $this->addToModel('uri', m_website_services_PageService::getInstance()->getDynamicUrl($document));
            $this->addToModel('numPage', $numPage);
        }
    }
}